#!/bin/bash
export LC_ALL=C
in="$1"
objout="$2"
kastout="$3"
trampout="$4"
cp "$in" "$objout"
size=`du -b "$in" | cut -f1`
len=`od -An -t u8 -j $(($size-13)) -N8 $in`
tramplen=`od -An -t u8 -j $(($size-21)) -N8 $in`
version=`dd --version | head -1 | awk '{print $3}'`
if [ "8.16" = "`printf "8.16\n%s" "$version" | sort -V | head -1`" ]; then
  dd if="$in" of="$kastout" iflag=skip_bytes,count_bytes skip=$(($size-21-$len-$tramplen)) "count=$len" >/dev/null 2>&1
  dd if="$in" of="$trampout" iflag=skip_bytes,count_bytes skip=$(($size-21-$tramplen)) "count=$tramplen" > /dev/null 2>&1
else
  dd if="$in" of="$kastout" bs=1 skip=$(($size-21-$len-$tramplen)) "count=$len" >/dev/null 2>&1
  dd if="$in" of="$trampout" bs=1 skip=$(($size-21-$tramplen)) "count=$tramplen" > /dev/null 2>&1
fi
